package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsGonggaoMapper;
import net.anzhuo.entity.GsGonggao;
import net.anzhuo.service.GsGonggaoService;

@Service
public class GsGonggaoServiceImpl implements GsGonggaoService {

	@Autowired
	private GsGonggaoMapper gsGonggaoMapper;

	@Override
	public PaginationVO<GsGonggao> getListWithPage(GsGonggao gsGonggao) {
		PaginationVO<GsGonggao> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsGonggaoMapper.getByCoMd5(gsGonggao.getCoMd5()));
		paginationVO.setTotalCount(gsGonggaoMapper.getCount(gsGonggao.getCoMd5()));
		
		int totalePage=((gsGonggaoMapper.getCount(gsGonggao.getCoMd5())-1)  / gsGonggao.getPageSize())+1;
		paginationVO.setTotalPage(totalePage);
		paginationVO.setPageNo(gsGonggao.getPageNo());
		return paginationVO;
	}

	@Override
	public GsGonggao getById(Long id) {
		return gsGonggaoMapper.getById(id);
	}

	@Override
	public List<GsGonggao> getByCoMd5(String coMd5) {
		return gsGonggaoMapper.getByCoMd5(coMd5);
	}

	
	@Override
	public List<GsGonggao> getByUpdateTime(GsGonggao gsGonggao) {
		return gsGonggaoMapper.getByUpdateTime(gsGonggao);
	}
	
	@Override
	public GsGonggao getByMd5(String md5) {
		return gsGonggaoMapper.getByMd5(md5);
	}

	
	
	@Override
	public List<GsGonggao> getList() {
		return gsGonggaoMapper.getList();
	}

	@Override
	public List<GsGonggao> getList(GsGonggao gsGonggao) {
		return gsGonggaoMapper.getListByQuery(gsGonggao);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsGonggao gsGonggao) {
		gsGonggaoMapper.update(gsGonggao);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsGonggao gsGonggao) {
		gsGonggaoMapper.save(gsGonggao);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsGonggao gsGonggao) {
		
		gsGonggaoMapper.delete(gsGonggao);
	}
}
